<template>
	<div class="components-container">
        <div class="header-form">
             <div class="layui-inline">
                <label class="layui-form-label">员工姓名</label>
                 <div class="layui-input-inline">
                    <el-input v-model="selectData.stanameLike" placeholder="请输入姓名"></el-input>
                 </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">所属部门</label>
                 <div class="layui-input-inline">
                  <el-select v-model="selectData.stadptidEquals" placeholder="请选择部门">
                      <el-option label="全部" :value="null"></el-option>
                      <el-option v-for="item in stadptTypes"
                              :key="item.value"
                              :label="item.label"
                              :value="item.value"
                              >
                      </el-option>
                  </el-select>
                 </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">员工类型</label>
                 <div class="layui-input-inline">
                    <el-select v-model="selectData.stacodnameEqual" placeholder="请选择类型">
                        <el-option label="全部" :value="null"></el-option>
                        <el-option v-for="item in staffTypes"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                                >
                        </el-option>
                    </el-select>
                 </div>
            </div>
            <el-button type="primary" @click="btnSearch" >搜索</el-button>
            <el-button  @click="btnRepeat" >重置</el-button>
        </div>
        <div>
            <ul class="toolList">
                <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
                    <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
                </li>
            </ul>
        </div>
        <dataTable :headList="headList" :dataList="dataList" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>

        <staffManageMain ref="sweetModalMain" :orderType="order" @refreshData="getData"></staffManageMain>
	</div>

</template>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.el-button + .el-button {
  margin-left: 0;
}
</style>
<script>
import staffManageMain from "./staffManageMain";
import dataTable from "@/components/Table/DataTable";
import apiBase from "@/api/apiBase.js";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import { manage } from "@/mixins/managePage.js";

const ADD = "新增";
const MODIFY = "修改";
const DELETE = "删除";
const INFO = "详情";
const DIMISS = "离职";
const RESTOR = "复职";

export default {
  name: "staffManage",
  mixins: [manage],
  data() {
    return {
      loading: false,
      headList: [],
      selectData: {},
      staffData: {},

      stadptTypes: [],
      staffTypes: [],
      sexTypes: [],
      cardTypes: [],
      culTypes: []
    };
  },
  methods: {
    //员工查询
    getData() {
      let data = {
        PageIndex: this.pageOrder.currentPage,
        PageSize: this.pageOrder.pageSize,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: JSON.parse(JSON.stringify(this.selectData))
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Staff.Query,
        res => {
          this.dataList = res.data.content.OutData;
          this.pageOrder.totalNum = res.data.content.RecordCount;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //获取部门
    getStaffDept() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Staff.QueryDept,
        res => {
          let deptTypeData = res.data.content.OutData,
            legendsUsersData = deptTypeData.map(item => ({
              label: item.DPTNAME,
              value: item.DPTID
            }));
          this.stadptTypes = legendsUsersData;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //获取员工类型
    getStaffTypes() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Code.GetStaType,
        res => {
          let staTypeData = res.data.content,
            legendsUsersData = staTypeData.map(item => ({
              label: item.CodeName,
              value: item.CodeValue
            }));
          this.staffTypes = legendsUsersData;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //获取表头
    getStaffColumns() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Column.GetStaffColumns,
        res => {
          this.headList = res.data.content;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //获取性别
    getStaffSex() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Code.GetSex,
        res => {
          let sexTypeData = res.data.content,
            legendsUsersData = sexTypeData.map(item => ({
              label: item.CodeName,
              value: item.CodeValue 
            }));
          this.sexTypes = legendsUsersData;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //获取证件类型
    getCardTypes() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Code.GetCardType,
        res => {
          let cardTypeData = res.data.content,
            legendsUsersData = cardTypeData.map(item => ({
              label: item.CodeName,
              value: item.CodeValue
            }));
          this.cardTypes = legendsUsersData;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //获取文化程度
    getCulTypes() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Code.GetCulturaldegree,
        res => {
          let culTypeData = res.data.content,
            legendsUsersData = culTypeData.map(item => ({
              label: item.CodeName,
              value: item.CodeValue
            }));
          this.culTypes = legendsUsersData;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //功能操作
    operate(order) {
      this.order = order;
      this.dataRepeat();
      switch (this.order) {
        case ADD:
          this.$refs.sweetModalMain.open(this.order);
          break;
        case MODIFY:
        case INFO:
          this.$refs.sweetModalMain.open(this.order, this.currentRow.STAID);
          break;
        case DELETE:
        case DIMISS:
        case RESTOR:
          this.$refs.sweetModalMain.open(this.order, this.currentRow.STAID);
          break;
        default:
      }
    },
    //查询条件重置
    btnRepeat() {
      this.selectData = {};
      this.getData();
    },
    btnShow(btn) {
      let status = '';
      if (this.currentRow) {
        status = this.currentRow.STASTATUS;
      }
      switch (btn) {
        case ADD:
          return true;
          break;
        case INFO:
        case MODIFY:
        case DELETE:
          return status !== '';
          break;
        case DIMISS:
          return status === '正常';
          break;
        case RESTOR:
          return status === '离职';
        default:
      }
    },
    //数据重置
    dataRepeat() {
      this.staffData = {};
    }
  },
  components: {
    staffManageMain,
    dataTable
  },
  mounted() {},
  created() {
    this.getData();
    this.getStaffTypes();
    this.getStaffDept();
    this.getStaffColumns();
    this.getStaffSex();
    this.getCardTypes();
    this.getCulTypes();
  }
};
</script>